using NetMigration.DAOs;
using NetMigration.Factories;

namespace NetMigration.Services
{
    public class VersionService : IVersionService
    {
        private readonly IVersionDAO versionDAO;

        public VersionService(IMigrationFactory factory)
        {
            versionDAO = factory.CreateVersionDAO();
        }

        public void InsertOrUpdateVersion(int version)
        {
            if (versionDAO.IsVersionExist())
            {
                versionDAO.UpdateVersion(version);
            }
            else
            {
                versionDAO.CreateVersion();
                versionDAO.UpdateVersion(version);
            }
        }

        public int GetCurrentVersion()
        {
            return versionDAO.GetCurrentVersion();
        }
    }
}